package com.zzf.guigu.Thread;

/**
 * @Author ZZF
 * @Date 2021-08-26-18:08
 */
public class AccountTest1 {
    public static void main(String[] args) {
        Account1 account1 = new Account1(0);
        Thread thread = new Thread(new Customer1(account1));
        thread.setName("线程1");
        Thread thread1 = new Thread(new Customer1(account1));
        thread1.setName("线程2");
        thread.start();
        thread1.start();
    }
}

class Account1 {

    private double blance;

    public Account1(double blance) {
        this.blance = blance;
    }

    public synchronized void cq(double amt) {
        if (amt > 0) {
            blance += amt;
            System.out.println(Thread.currentThread().getName() + "存钱成功，余额为：" + blance);
        }
    }

}

class Customer1 implements Runnable {

    private Account1 account;

    public Customer1(Account1 account) {
        this.account = account;
    }

    @Override
    public void run() {
        for (int i = 0; i < 3; i++) {
            account.cq(1000);
        }
    }
}
